﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.joinConvert
{
	// Token: 0x0200042E RID: 1070
	public class joinConverter
	{
		// Token: 0x17000985 RID: 2437
		// (get) Token: 0x0600294B RID: 10571 RVA: 0x0033D671 File Offset: 0x0033B871
		public virtual string ErrorMessage
		{
			get
			{
				return this.errorMessage;
			}
		}

		// Token: 0x0600294C RID: 10572 RVA: 0x0033D679 File Offset: 0x0033B879
		public joinConverter(string sql, EDbVendor vendor)
		{
			this.query = sql;
			this.vendor = vendor;
		}

		// Token: 0x17000986 RID: 2438
		// (get) Token: 0x0600294D RID: 10573 RVA: 0x0033D69A File Offset: 0x0033B89A
		public virtual string Query
		{
			get
			{
				return Regex.Replace(this.query, "(?m)^[\t]*\r?\n", "");
			}
		}

		// Token: 0x0600294E RID: 10574 RVA: 0x0033D6B4 File Offset: 0x0033B8B4
		public virtual int convert()
		{
			TGSharpSqlParser tGSharpSqlParser = new TGSharpSqlParser(this.vendor);
			tGSharpSqlParser.sqltext = this.query;
			this.ErrorNo = tGSharpSqlParser.parse();
			if (this.ErrorNo != 0)
			{
				this.errorMessage = tGSharpSqlParser.Errormessage;
				return this.ErrorNo;
			}
			TCustomSqlStatement tcustomSqlStatement = tGSharpSqlParser.sqlstatements.get(0);
			this.analyzeSelect(tcustomSqlStatement);
			this.query = tcustomSqlStatement.ToScript();
			return this.ErrorNo;
		}

		// Token: 0x0600294F RID: 10575 RVA: 0x0033D726 File Offset: 0x0033B926
		private bool isNameOfTable(TTable table, string name)
		{
			return name != null && table.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase);
		}

		// Token: 0x06002950 RID: 10576 RVA: 0x0033D73A File Offset: 0x0033B93A
		private bool isAliasOfTable(TTable table, string alias)
		{
			return table.AliasClause != null && alias != null && table.AliasClause.ToString().Equals(alias, StringComparison.CurrentCultureIgnoreCase);
		}

		// Token: 0x06002951 RID: 10577 RVA: 0x0033D75D File Offset: 0x0033B95D
		private bool isNameOrAliasOfTable(TTable table, string str)
		{
			return this.isAliasOfTable(table, str) || this.isNameOfTable(table, str);
		}

		// Token: 0x06002952 RID: 10578 RVA: 0x0033D774 File Offset: 0x0033B974
		private bool areTableJoined(TTable lefttable, TTable righttable, List<joinConverter.JoinCondition> jrs)
		{
			bool flag = false;
			for (int i = 0; i < jrs.Count; i++)
			{
				joinConverter.JoinCondition joinCondition = jrs[i];
				if (!joinCondition.used.Value)
				{
					flag = (this.isNameOrAliasOfTable(lefttable, joinCondition.lefttable) && this.isNameOrAliasOfTable(righttable, joinCondition.righttable));
					if (flag)
					{
						break;
					}
					flag = (this.isNameOrAliasOfTable(lefttable, joinCondition.righttable) && this.isNameOrAliasOfTable(righttable, joinCondition.lefttable));
					if (flag)
					{
						break;
					}
				}
			}
			return flag;
		}

		// Token: 0x06002953 RID: 10579 RVA: 0x0033D7F0 File Offset: 0x0033B9F0
		private EJoinType getJoinType(List<joinConverter.JoinCondition> jrs)
		{
			for (int i = 0; i < jrs.Count; i++)
			{
				if (jrs[i].jt == joinConverter.jointype.left)
				{
					return EJoinType.left;
				}
				if (jrs[i].jt == joinConverter.jointype.leftOuter)
				{
					return EJoinType.leftouter;
				}
				if (jrs[i].jt == joinConverter.jointype.right)
				{
					return EJoinType.right;
				}
				if (jrs[i].jt == joinConverter.jointype.rightOuter)
				{
					return EJoinType.rightouter;
				}
				if (jrs[i].jt == joinConverter.jointype.full)
				{
					return EJoinType.full;
				}
				if (jrs[i].jt == joinConverter.jointype.fullOuter)
				{
					return EJoinType.fullouter;
				}
				if (jrs[i].jt == joinConverter.jointype.cross)
				{
					return EJoinType.cross;
				}
				if (jrs[i].jt == joinConverter.jointype.join)
				{
					return EJoinType.join;
				}
				if (jrs[i].jt == joinConverter.jointype.inner)
				{
					return EJoinType.inner;
				}
			}
			return EJoinType.join;
		}

		// Token: 0x06002954 RID: 10580 RVA: 0x0033D8B0 File Offset: 0x0033BAB0
		private List<joinConverter.JoinCondition> getJoinCondition(TTable lefttable, TTable righttable, List<joinConverter.JoinCondition> jrs)
		{
			List<joinConverter.JoinCondition> list = new List<joinConverter.JoinCondition>();
			for (int i = 0; i < jrs.Count; i++)
			{
				joinConverter.JoinCondition joinCondition = jrs[i];
				if (!joinCondition.used.Value)
				{
					if (this.isNameOrAliasOfTable(lefttable, joinCondition.lefttable) && this.isNameOrAliasOfTable(righttable, joinCondition.righttable))
					{
						list.Add(joinCondition);
						joinCondition.used = new bool?(true);
					}
					else if (this.isNameOrAliasOfTable(lefttable, joinCondition.righttable) && this.isNameOrAliasOfTable(righttable, joinCondition.lefttable))
					{
						if (joinCondition.jt == joinConverter.jointype.left)
						{
							joinCondition.jt = joinConverter.jointype.right;
						}
						else if (joinCondition.jt == joinConverter.jointype.right)
						{
							joinCondition.jt = joinConverter.jointype.left;
						}
						list.Add(joinCondition);
						joinCondition.used = new bool?(true);
					}
					else if (joinCondition.lefttable == null && (this.isNameOrAliasOfTable(lefttable, joinCondition.righttable) || this.isNameOrAliasOfTable(righttable, joinCondition.righttable)))
					{
						list.Add(joinCondition);
						joinCondition.used = new bool?(true);
					}
					else if (joinCondition.righttable == null && (this.isNameOrAliasOfTable(lefttable, joinCondition.lefttable) || this.isNameOrAliasOfTable(righttable, joinCondition.lefttable)))
					{
						if (joinCondition.jt == joinConverter.jointype.left)
						{
							joinCondition.jt = joinConverter.jointype.right;
						}
						else if (joinCondition.jt == joinConverter.jointype.right)
						{
							joinCondition.jt = joinConverter.jointype.left;
						}
						list.Add(joinCondition);
						joinCondition.used = new bool?(true);
					}
				}
			}
			return list;
		}

		// Token: 0x06002955 RID: 10581 RVA: 0x0033DA18 File Offset: 0x0033BC18
		private void analyzeSelect(TCustomSqlStatement stmt)
		{
			if (stmt is TSelectSqlStatement)
			{
				TSelectSqlStatement tselectSqlStatement = (TSelectSqlStatement)stmt;
				if (tselectSqlStatement.CombinedQuery)
				{
					this.analyzeSelect(tselectSqlStatement.LeftStmt);
					this.analyzeSelect(tselectSqlStatement.RightStmt);
					return;
				}
				for (int i = 0; i < tselectSqlStatement.Statements.size(); i++)
				{
					if (tselectSqlStatement.Statements.get(i) is TSelectSqlStatement)
					{
						this.analyzeSelect((TSelectSqlStatement)tselectSqlStatement.Statements.get(i));
					}
				}
				if (tselectSqlStatement.tables.size() == 1)
				{
					return;
				}
				if (tselectSqlStatement.WhereClause == null)
				{
					if (tselectSqlStatement.tables.size() > 1 && !this.hasJoin(tselectSqlStatement.joins))
					{
						for (int j = tselectSqlStatement.joins.size() - 1; j >= 0; j--)
						{
							tselectSqlStatement.joins.removeJoin(j);
						}
						TJoin tjoin = new TJoin();
						tselectSqlStatement.joins.addJoin(tjoin);
						tjoin.Table = tselectSqlStatement.tables.getTable(0);
						for (int k = 1; k < tselectSqlStatement.tables.size(); k++)
						{
							TJoinItem tjoinItem = new TJoinItem();
							tjoin.JoinItems.addJoinItem(tjoinItem);
							tjoinItem.JoinType = EJoinType.cross;
							tjoinItem.Table = tselectSqlStatement.tables[k];
						}
						return;
					}
				}
				else
				{
					joinConverter.getJoinConditionVisitor getJoinConditionVisitor = new joinConverter.getJoinConditionVisitor(this);
					tselectSqlStatement.WhereClause.Condition.preOrderTraverse(getJoinConditionVisitor);
					List<joinConverter.JoinCondition> jrs = getJoinConditionVisitor.Jrs;
					if (tselectSqlStatement.joins != null && tselectSqlStatement.joins.size() > 0)
					{
						for (int l = 0; l < tselectSqlStatement.joins.size(); l++)
						{
							TJoin join = tselectSqlStatement.joins.getJoin(l);
							for (int m = 0; m < join.JoinItems.size(); m++)
							{
								TJoinItem joinItem = join.JoinItems.getJoinItem(m);
								joinConverter.JoinCondition joinCondition = new joinConverter.JoinCondition(this);
								joinCondition.expr = joinItem.OnCondition;
								joinCondition.used = new bool?(false);
								joinCondition.lexpr = joinCondition.expr.LeftOperand;
								joinCondition.rexpr = joinCondition.expr.RightOperand;
								joinCondition.lefttable = this.getExpressionTable(joinCondition.lexpr);
								joinCondition.righttable = this.getExpressionTable(joinCondition.rexpr);
								if (joinItem.JoinType == EJoinType.inner)
								{
									joinCondition.jt = joinConverter.jointype.inner;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.left)
								{
									joinCondition.jt = joinConverter.jointype.left;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.leftouter)
								{
									joinCondition.jt = joinConverter.jointype.leftOuter;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.right)
								{
									joinCondition.jt = joinConverter.jointype.right;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.rightouter)
								{
									joinCondition.jt = joinConverter.jointype.rightOuter;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.full)
								{
									joinCondition.jt = joinConverter.jointype.full;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.fullouter)
								{
									joinCondition.jt = joinConverter.jointype.fullOuter;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.join)
								{
									joinCondition.jt = joinConverter.jointype.join;
									jrs.Add(joinCondition);
								}
								if (joinItem.JoinType == EJoinType.cross)
								{
									joinCondition.jt = joinConverter.jointype.cross;
									jrs.Add(joinCondition);
								}
							}
						}
					}
					bool[] array = new bool[tselectSqlStatement.tables.size()];
					for (int n = 0; n < tselectSqlStatement.tables.size(); n++)
					{
						array[n] = false;
					}
					array[0] = true;
					List<joinConverter.FromClause> list = new List<joinConverter.FromClause>();
					bool flag;
					do
					{
						flag = false;
						for (int num = 0; num < tselectSqlStatement.tables.size(); num++)
						{
							TTable table = tselectSqlStatement.tables.getTable(num);
							TTable ttable = null;
							TTable ttable2 = null;
							for (int num2 = num + 1; num2 < tselectSqlStatement.tables.size(); num2++)
							{
								TTable table2 = tselectSqlStatement.tables.getTable(num2);
								if (this.areTableJoined(table, table2, jrs))
								{
									if (array[num] && !array[num2])
									{
										ttable = table;
										ttable2 = table2;
									}
									else if (!array[num] && array[num2])
									{
										ttable = table2;
										ttable2 = table;
									}
									if (ttable != null && ttable2 != null)
									{
										List<joinConverter.JoinCondition> joinCondition2 = this.getJoinCondition(ttable, ttable2, jrs);
										if (joinCondition2.Count != 0)
										{
											joinConverter.FromClause fromClause = new joinConverter.FromClause(this);
											fromClause.table = ttable;
											fromClause.joinTable = ttable2;
											fromClause.joinClause = this.getJoinType(joinCondition2);
											string text = "";
											for (int num3 = 0; num3 < joinCondition2.Count; num3++)
											{
												text += joinCondition2[num3].expr.ToString();
												if (num3 != joinCondition2.Count - 1)
												{
													text += " and ";
												}
												joinCondition2[num3].expr.remove();
											}
											fromClause.condition = text;
											list.Add(fromClause);
											array[num] = true;
											array[num2] = true;
											flag = true;
										}
									}
								}
							}
						}
					}
					while (flag);
					for (int num4 = 0; num4 < jrs.Count; num4++)
					{
						joinConverter.JoinCondition joinCondition3 = jrs[num4];
						if (!joinCondition3.used.Value)
						{
							for (int num5 = list.Count - 1; num5 >= 0; num5--)
							{
								if (this.isNameOrAliasOfTable(list[num5].joinTable, joinCondition3.lefttable) || this.isNameOrAliasOfTable(list[num5].joinTable, joinCondition3.righttable))
								{
									joinConverter.FromClause fromClause2 = list[num5];
									fromClause2.condition = fromClause2.condition + " and " + joinCondition3.expr.ToString();
									joinCondition3.used = new bool?(true);
									joinCondition3.expr.remove();
									break;
								}
							}
						}
					}
					for (int num6 = 0; num6 < tselectSqlStatement.tables.size(); num6++)
					{
						if (!array[num6])
						{
							this.ErrorNo++;
							this.errorMessage += string.Format("{0}Error {1:D}, Message: {2}", "\r\n", this.ErrorNo, "This table has no join condition: " + tselectSqlStatement.tables.getTable(num6).FullName);
						}
					}
					list.Sort(new joinConverter.ComparatorAnonymousInnerClass(this, tselectSqlStatement));
					list.Sort(new joinConverter.ComparatorAnonymousInnerClass2(this, list));
					for (int num7 = tselectSqlStatement.joins.size() - 1; num7 >= 0; num7--)
					{
						tselectSqlStatement.joins.removeJoin(num7);
					}
					TJoin tjoin2 = new TJoin();
					tselectSqlStatement.joins.addJoin(tjoin2);
					tjoin2.Table = tselectSqlStatement.tables.getTable(0);
					for (int num8 = 0; num8 < list.Count; num8++)
					{
						joinConverter.FromClause fromClause3 = list[num8];
						TJoinItem tjoinItem2 = new TJoinItem();
						tjoin2.JoinItems.addJoinItem(tjoinItem2);
						tjoinItem2.JoinType = fromClause3.joinClause;
						tjoinItem2.Table = fromClause3.joinTable;
						tjoinItem2.OnCondition = tselectSqlStatement.GSharpSqlParser.parseExpression(fromClause3.condition);
					}
					if (tselectSqlStatement.WhereClause.Condition.ToScript().Trim().Length == 0)
					{
						tselectSqlStatement.WhereClause = null;
						return;
					}
				}
			}
			else if (stmt.Statements != null)
			{
				for (int num9 = 0; num9 < stmt.Statements.size(); num9++)
				{
					this.analyzeSelect(stmt.Statements.get(num9));
				}
			}
		}

		// Token: 0x06002956 RID: 10582 RVA: 0x0033E1B0 File Offset: 0x0033C3B0
		private bool hasJoin(TJoinList joins)
		{
			if (joins == null)
			{
				return false;
			}
			for (int i = 0; i < joins.size(); i++)
			{
				if (joins.getJoin(i).JoinItems != null && joins.getJoin(i).JoinItems.size() > 0)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x06002957 RID: 10583 RVA: 0x0033E1F8 File Offset: 0x0033C3F8
		private string getFullNameWithAliasString(TTable table)
		{
			if (table.Subquery != null)
			{
				if (table.AliasClause != null)
				{
					TSelectSqlStatement subquery = table.Subquery;
					return ((subquery != null) ? subquery.ToString() : null) + " " + table.AliasClause.ToString();
				}
				return table.Subquery.ToString();
			}
			else
			{
				if (table.FullName != null)
				{
					return table.FullNameWithAliasString;
				}
				return table.ToString();
			}
		}

		// Token: 0x06002958 RID: 10584 RVA: 0x0033E260 File Offset: 0x0033C460
		private string getExpressionTable(TExpression expr)
		{
			if (expr.ExpressionType == EExpressionType.function_t)
			{
				if (expr.FunctionCall.Args.size() == 1)
				{
					return this.getExpressionTable(expr.FunctionCall.Args.getExpression(0));
				}
			}
			else
			{
				if (expr.ObjectOperand != null)
				{
					return expr.ObjectOperand.ObjectString;
				}
				if (expr.LeftOperand != null && expr.LeftOperand.ObjectOperand != null)
				{
					return expr.LeftOperand.ObjectOperand.ObjectString;
				}
				if (expr.RightOperand != null && expr.RightOperand.ObjectOperand != null)
				{
					return expr.RightOperand.ObjectOperand.ObjectString;
				}
			}
			return null;
		}

		// Token: 0x04001EA3 RID: 7843
		private string errorMessage = "";

		// Token: 0x04001EA4 RID: 7844
		private int ErrorNo;

		// Token: 0x04001EA5 RID: 7845
		private string query;

		// Token: 0x04001EA6 RID: 7846
		private EDbVendor vendor;

		// Token: 0x02000455 RID: 1109
		internal enum jointype
		{
			// Token: 0x040020AA RID: 8362
			inner,
			// Token: 0x040020AB RID: 8363
			left,
			// Token: 0x040020AC RID: 8364
			leftOuter,
			// Token: 0x040020AD RID: 8365
			right,
			// Token: 0x040020AE RID: 8366
			rightOuter,
			// Token: 0x040020AF RID: 8367
			cross,
			// Token: 0x040020B0 RID: 8368
			join,
			// Token: 0x040020B1 RID: 8369
			full,
			// Token: 0x040020B2 RID: 8370
			fullOuter
		}

		// Token: 0x02000456 RID: 1110
		internal class FromClause
		{
			// Token: 0x0600299C RID: 10652 RVA: 0x0033E845 File Offset: 0x0033CA45
			public FromClause(joinConverter outerInstance)
			{
				this.outerInstance = outerInstance;
			}

			// Token: 0x040020B3 RID: 8371
			private readonly joinConverter outerInstance;

			// Token: 0x040020B4 RID: 8372
			internal TTable table;

			// Token: 0x040020B5 RID: 8373
			internal TTable joinTable;

			// Token: 0x040020B6 RID: 8374
			internal EJoinType joinClause;

			// Token: 0x040020B7 RID: 8375
			internal string condition;
		}

		// Token: 0x02000457 RID: 1111
		internal class JoinCondition
		{
			// Token: 0x0600299D RID: 10653 RVA: 0x0033E854 File Offset: 0x0033CA54
			public JoinCondition(joinConverter outerInstance)
			{
				this.outerInstance = outerInstance;
			}

			// Token: 0x040020B8 RID: 8376
			private readonly joinConverter outerInstance;

			// Token: 0x040020B9 RID: 8377
			public string lefttable;

			// Token: 0x040020BA RID: 8378
			public string righttable;

			// Token: 0x040020BB RID: 8379
			public joinConverter.jointype jt;

			// Token: 0x040020BC RID: 8380
			public bool? used;

			// Token: 0x040020BD RID: 8381
			public TExpression lexpr;

			// Token: 0x040020BE RID: 8382
			public TExpression rexpr;

			// Token: 0x040020BF RID: 8383
			public TExpression expr;
		}

		// Token: 0x02000458 RID: 1112
		internal class getJoinConditionVisitor : IExpressionVisitor
		{
			// Token: 0x0600299E RID: 10654 RVA: 0x0033E863 File Offset: 0x0033CA63
			public getJoinConditionVisitor(joinConverter outerInstance)
			{
				this.outerInstance = outerInstance;
			}

			// Token: 0x1700098D RID: 2445
			// (get) Token: 0x0600299F RID: 10655 RVA: 0x0033E889 File Offset: 0x0033CA89
			public virtual List<joinConverter.JoinCondition> Jrs
			{
				get
				{
					return this.jrs;
				}
			}

			// Token: 0x060029A0 RID: 10656 RVA: 0x0033E891 File Offset: 0x0033CA91
			internal virtual bool is_compare_condition(EExpressionType t)
			{
				return t == EExpressionType.simple_comparison_t || t == EExpressionType.group_comparison_t || t == EExpressionType.in_t;
			}

			// Token: 0x060029A1 RID: 10657 RVA: 0x0033E8A4 File Offset: 0x0033CAA4
			internal virtual void analyzeJoinCondition(TExpression expr, TExpression parent_expr)
			{
				if (expr.GSharpSqlParser.DbVendor == EDbVendor.dbvmssql && (expr.ExpressionType == EExpressionType.left_join_t || expr.ExpressionType == EExpressionType.right_join_t))
				{
					this.analyzeMssqlJoinCondition(expr);
				}
				if (this.is_compare_condition(expr.ExpressionType))
				{
					TExpression leftOperand = expr.LeftOperand;
					TExpression rightOperand = expr.RightOperand;
					if (leftOperand.OracleOuterJoin || rightOperand.OracleOuterJoin)
					{
						joinConverter.JoinCondition joinCondition = new joinConverter.JoinCondition(this.outerInstance);
						joinCondition.used = new bool?(false);
						joinCondition.lexpr = leftOperand;
						joinCondition.rexpr = rightOperand;
						joinCondition.expr = expr;
						if (leftOperand.OracleOuterJoin)
						{
							joinCondition.jt = joinConverter.jointype.rightOuter;
							leftOperand.endToken.String = "";
						}
						if (rightOperand.OracleOuterJoin)
						{
							joinCondition.jt = joinConverter.jointype.leftOuter;
							rightOperand.endToken.String = "";
						}
						joinCondition.lefttable = this.outerInstance.getExpressionTable(leftOperand);
						joinCondition.righttable = this.outerInstance.getExpressionTable(rightOperand);
						this.jrs.Add(joinCondition);
						return;
					}
					if (leftOperand.ExpressionType == EExpressionType.simple_object_name_t && !leftOperand.ToString().StartsWith(":", StringComparison.Ordinal) && !leftOperand.ToString().StartsWith("?", StringComparison.Ordinal) && rightOperand.ExpressionType == EExpressionType.simple_object_name_t && !rightOperand.ToString().StartsWith(":", StringComparison.Ordinal) && !rightOperand.ToString().StartsWith("?", StringComparison.Ordinal))
					{
						joinConverter.JoinCondition joinCondition2 = new joinConverter.JoinCondition(this.outerInstance);
						joinCondition2.used = new bool?(false);
						joinCondition2.lexpr = leftOperand;
						joinCondition2.rexpr = rightOperand;
						joinCondition2.expr = expr;
						joinCondition2.jt = joinConverter.jointype.join;
						joinCondition2.lefttable = this.outerInstance.getExpressionTable(leftOperand);
						joinCondition2.righttable = this.outerInstance.getExpressionTable(rightOperand);
						this.jrs.Add(joinCondition2);
					}
				}
			}

			// Token: 0x060029A2 RID: 10658 RVA: 0x0033EA88 File Offset: 0x0033CC88
			internal virtual void analyzeMssqlJoinCondition(TExpression expr)
			{
				TExpression leftOperand = expr.LeftOperand;
				TExpression rightOperand = expr.RightOperand;
				joinConverter.JoinCondition joinCondition = new joinConverter.JoinCondition(this.outerInstance);
				joinCondition.used = new bool?(false);
				joinCondition.lexpr = leftOperand;
				joinCondition.rexpr = rightOperand;
				joinCondition.expr = expr;
				expr.OperatorToken.String = "=";
				if (expr.ExpressionType == EExpressionType.left_join_t)
				{
					joinCondition.jt = joinConverter.jointype.left;
				}
				if (expr.ExpressionType == EExpressionType.right_join_t)
				{
					joinCondition.jt = joinConverter.jointype.right;
				}
				joinCondition.lefttable = this.outerInstance.getExpressionTable(leftOperand);
				joinCondition.righttable = this.outerInstance.getExpressionTable(rightOperand);
				this.jrs.Add(joinCondition);
			}

			// Token: 0x060029A3 RID: 10659 RVA: 0x0033EB34 File Offset: 0x0033CD34
			public virtual bool exprVisit(TParseTreeNode pNode, bool isLeafNode)
			{
				TExpression texpression = (TExpression)pNode;
				this.analyzeJoinCondition(texpression, texpression);
				return true;
			}

			// Token: 0x040020C0 RID: 8384
			private readonly joinConverter outerInstance;

			// Token: 0x040020C1 RID: 8385
			internal bool? isFirstExpr = new bool?(true);

			// Token: 0x040020C2 RID: 8386
			internal List<joinConverter.JoinCondition> jrs = new List<joinConverter.JoinCondition>();
		}

		// Token: 0x02000459 RID: 1113
		private class ComparatorAnonymousInnerClass : IComparer<joinConverter.FromClause>
		{
			// Token: 0x060029A4 RID: 10660 RVA: 0x0033EB51 File Offset: 0x0033CD51
			public ComparatorAnonymousInnerClass(joinConverter outerInstance, TSelectSqlStatement select)
			{
				this.outerInstance = outerInstance;
				this.select = select;
			}

			// Token: 0x060029A5 RID: 10661 RVA: 0x0033EB67 File Offset: 0x0033CD67
			public virtual int Compare(joinConverter.FromClause o1, joinConverter.FromClause o2)
			{
				return this.indexOf(this.select, o1.joinTable) - this.indexOf(this.select, o2.joinTable);
			}

			// Token: 0x060029A6 RID: 10662 RVA: 0x0033EB90 File Offset: 0x0033CD90
			private int indexOf(TSelectSqlStatement select, TTable joinTable)
			{
				TTableList tables = select.tables;
				for (int i = 0; i < tables.size(); i++)
				{
					if (joinTable != null && tables.getTable(i).Equals(joinTable))
					{
						return i;
					}
				}
				return -1;
			}

			// Token: 0x040020C3 RID: 8387
			private readonly joinConverter outerInstance;

			// Token: 0x040020C4 RID: 8388
			private TSelectSqlStatement select;
		}

		// Token: 0x0200045A RID: 1114
		private class ComparatorAnonymousInnerClass2 : IComparer<joinConverter.FromClause>
		{
			// Token: 0x060029A7 RID: 10663 RVA: 0x0033EBCA File Offset: 0x0033CDCA
			public ComparatorAnonymousInnerClass2(joinConverter outerInstance, List<joinConverter.FromClause> fromClauses)
			{
				this.outerInstance = outerInstance;
				this.fromClauses = fromClauses;
			}

			// Token: 0x060029A8 RID: 10664 RVA: 0x0033EBE0 File Offset: 0x0033CDE0
			public virtual int Compare(joinConverter.FromClause o1, joinConverter.FromClause o2)
			{
				if (o1.table.Equals(o2.joinTable))
				{
					return 1;
				}
				if (o2.table.Equals(o1.joinTable))
				{
					return -1;
				}
				return this.fromClauses.IndexOf(o1) - this.fromClauses.IndexOf(o2);
			}

			// Token: 0x040020C5 RID: 8389
			private readonly joinConverter outerInstance;

			// Token: 0x040020C6 RID: 8390
			private List<joinConverter.FromClause> fromClauses;
		}
	}
}
